// pages/hotel/index.js

const bg = 'https://pic.616pic.com/bg_w1180/00/00/02/zGDDPXuN2S.jpg'

const headImg = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fd064be90-6b8c-4a6d-9721-837206fbb4a7%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1696759051&t=b90e0bf861e41c30214fc739ae66343f'

const hotels = [
  'https://res.cngoldres.com/upload/2017/1011/30b836444f0411260a0afe76ea9576af.jpg',
  'https://x0.ifengimg.com/ucms/2021_04/C63B2D16D69D691EDC7D8C31E299988487E2C3C5_size144_w1080_h1402.jpg',
  'https://img2.baidu.com/it/u=2362882516,1616341177&fm=253&fmt=auto&app=138&f=JPEG?w=855&h=500'
]

const genList = (num) => {
  const ans = []
  for (let i = 0; i < num; i++) {
    ans.push({
      id: i,
      img: hotels[(i % hotels.length)]
    })
  }
  return ans
}

const { windowHeight } = wx.getSystemInfoSync()
const menuRect = wx.getMenuButtonBoundingClientRect()
const menuBottom = menuRect.bottom + 1

Page({

  /**
   * 页面的初始数据
   */
  data: {
    sheetHeight: windowHeight - menuBottom,
    initialSize: 0,
    minSize: 0,
    maxSize: 1,
    bg,
    headImg,
    list: genList(10),
    latitude: 23.099994,
    longitude: 113.324520,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getContext()
  },

  showHotel() {
    this.expand()
  },

  getContext() {
    this.createSelectorQuery()
      .select(".sheet")
      .node()
      .exec(res => {
        this.sheetContext = res[0].node
        console.info('@@@ sheetContext: ', this.sheetContext)
      })
  },

  expand() {
    const size = 0.5
    this.sheetContext.scrollTo({
      size,
      pixels: 600,
      animated: true,
      duration: 300,
      easingFunction: 'ease'
    })
  },

  collapse() {
    this.sheetContext.scrollTo({
      size: 0,
      animated: true,
    })
  },


  onSizeUpdate() {
    'worklet'

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})